package com.lp.biz.operations.controller;

import com.lp.biz.operations.model.vo.BannerAdd;
import com.lp.biz.operations.service.BizRecommendBannerService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.BANNER;

/**
 * BizRecommendBannerController
 * @program: backend
 * @author Ke.Song
 * @since 2024-07-14 23:26:00
 */
@RestController
@RequestMapping("/banner")
public class BizRecommendBannerController {

    @Autowired
    private BizRecommendBannerService bannerService;

    /**
     * 获取Banner列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("")
    @PermissionAnnotation(menus = {BANNER})
    public CommonResult getBannerList(PageParams query) {
        return bannerService.getBannerList(query);
    }

    /**
     * 删除Banner
     * @param bannerId BannerId
     * @return 处理结果
     */
    @DeleteMapping("/{bannerId}")
    @PermissionAnnotation(menus = {BANNER})
    public CommonResult deleteBanner(@PathVariable Integer bannerId) {
        bannerService.deleteBanner(bannerId);
        return CommonResult.success();
    }

    /**
     * 增加/更新Banner
     * @param params Banner参数
     * @return 处理结果
     */
    @PostMapping("")
    @PermissionAnnotation(menus = {BANNER})
    public CommonResult addOrUpdateBanner(@RequestBody@Validated BannerAdd params) {
        bannerService.addOrUpdateBanner(params);
        return CommonResult.success();
    }
}
